/*************************************************
*                                                *
*  EasyBMP Cross-Platform Windows Bitmap Library *
*                                                *
*  Author: Paul Macklin                          *
*   email: macklin01@users.sourceforge.net       *
* support: http://easybmp.sourceforge.net        *
*                                                *
*          file: EasyBMP_VariousBMPutilities.h   *
*    date added: 05-02-2005                      *
* date modified: 12-01-2006                      *
*       version: 1.06                            *
*                                                *
*   License: BSD (revised/modified)              *
* Copyright: 2005-6 by the EasyBMP Project       *
*                                                *
* description: Defines BMP class                 *
*                                                *
*************************************************/

#ifndef _EasyBMP_BMP_h_
#define _EasyBMP_BMP_h_

bool EBMP_SafeFread( char* buffer, int size, int number, FILE* fp );
bool EBMP_EasyBMPcheckDataSize( void );

class BMP
{
private:

    int BitDepth;
    int Width;
    int Height;
    EBMP_RGBApixel** Pixels;
    EBMP_RGBApixel* Colors;
    int XPelsPerMeter;
    int YPelsPerMeter;

    ebmpBYTE* MetaData1;
    int SizeOfMetaData1;
    ebmpBYTE* MetaData2;
    int SizeOfMetaData2;

    bool BMP_Read32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row );
    bool BMP_Read24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row );
    bool BMP_Read8bitRow(  ebmpBYTE* Buffer, int BufferSize, int Row );
    bool BMP_Read4bitRow(  ebmpBYTE* Buffer, int BufferSize, int Row );
    bool BMP_Read1bitRow(  ebmpBYTE* Buffer, int BufferSize, int Row );

    bool BMP_Write32bitRow( ebmpBYTE* Buffer, int BufferSize, int Row );
    bool BMP_Write24bitRow( ebmpBYTE* Buffer, int BufferSize, int Row );
    bool BMP_Write8bitRow(  ebmpBYTE* Buffer, int BufferSize, int Row );
    bool BMP_Write4bitRow(  ebmpBYTE* Buffer, int BufferSize, int Row );
    bool BMP_Write1bitRow(  ebmpBYTE* Buffer, int BufferSize, int Row );

    ebmpBYTE BMP_FindClosestColor( EBMP_RGBApixel& input );

public:

    int BMP_TellBitDepth( void );
    int BMP_TellWidth( void );
    int BMP_TellHeight( void );
    int BMP_TellNumberOfColors( void );
    void BMP_SetDPI( int HorizontalDPI, int VerticalDPI );
    int BMP_TellVerticalDPI( void );
    int BMP_TellHorizontalDPI( void );

    BMP();
    BMP( BMP& Input );
    ~BMP();
    EBMP_RGBApixel* operator()(int i,int j);

    EBMP_RGBApixel BMP_GetPixel( int i, int j ) const;
    bool BMP_SetPixel( int i, int j, EBMP_RGBApixel NewPixel );

    bool BMP_CreateStandardColorTable( void );

    bool BMP_SetSize( int NewWidth, int NewHeight );
    bool BMP_SetBitDepth( int NewDepth );
    bool BMP_WriteToFile( const char* FileName );
    bool BMP_ReadFromFile( const char* FileName );

    EBMP_RGBApixel BMP_GetColor( int ColorNumber );
    bool BMP_SetColor( int ColorNumber, EBMP_RGBApixel NewColor );
};

#endif
